<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;

class Dealer extends Model
{
    use HasFactory;
    use Cachable;
    
    public static $levelMap = [
        1  => '形象店',
        2 => '普通店',
    ];

    protected $fillable = [
        'code','name','area_code','address','lat','lng','service_phone','online','level'
    ];

    protected $casts = [
        'level' => 'integer',
        'online' => 'boolean',
    ];

    public function getLevelChAttribute()
    {
        return self::$levelMap[$this->level];
    }

    public function series()
    {
        return $this->belongsToMany(VehicleSeries::class)->withTimestamps();
    }
    
}
